#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

class Solution {
public:
	string longestCommonPrefix(vector<string>& strs) {
		if (strs.size() == 0)
			return "";
		string pub = "";
		int min=strs[0].size();
		for (int i = 1; i < strs.size(); i++) {
			if (min > strs[i].size())
				min = strs[i].size();
		}
		for (int i = 0; i < min; i++)
		{
			char ch = strs[0][i];
			for (int j = 0; j < strs.size(); j++) {
				if (ch != strs[j][i])
					return pub;
			}
			pub.push_back(ch);
		}
		return pub;
	}
};

void main(){
	Solution s;
	vector<string> test = { "flower","flow","flight" };
	vector<string> test2 = { "dog","racecar","car" };
	s.longestCommonPrefix(test2);
}